<?php
	
	// 项目基础类
	namespace core;

	class core
	{
		public static $classMap = array();
        public $assign;
		static public function run()
		{
			$route = new \core\lib\route();
			$ctrlClass = $route->ctrl;
			$action = $route->action;
			// 控制器路径
			$ctrlFile = APP . '/ctrl/' . $ctrlClass . 'Ctrl.php';
            // 判断控制器文件是否存在
            $ctrlClass = '\\' . MODULE . '\ctrl\\' . $ctrlClass . 'Ctrl';
			if(is_file($ctrlFile)){
                include $ctrlFile;
                $ctrl = new $ctrlClass();
                $ctrl->$action();
			}else{
				throw new \Exception("找不到控制器" . $ctrlClass);
			}
		}


		// 自动加载类库
		static public function load($class)
		{
			if(isset($classMap[$class])){
				return false;
			}else{
				$class = str_replace('\\', '/', $class);
				$file = KXT . '/' . $class . '.php';
				// 判断一下文件是否存在
				if(is_file($file)){
					include $file;
					self::$classMap[$class] = $class;
				}else{
					return false;
				}
			}
		}


		// 模板赋值
        public function assign($name,$value)
        {
            $this->assign[$name] = $value;
        }

        // 模板渲染
        public function display($file)
        {
            $file = APP . '/view/' . $file;
            if(is_file($file)){
                extract($this->assign);
                include $file;
            }
        }
	}